<?php
require_once dirname(__DIR__) . '/public/cli.php';

use IYUU\sdk\ChatBot\Credential;
use IYUU\sdk\ChatBot\Profile\ClientProfile;
use IYUU\sdk\ChatBot\Profile\HttpProfile;
use IYUU\sdk\ChatBot\TencentCloudSDKException;
use IYUU\sdk\ChatBot\NlpClient;
use IYUU\sdk\ChatBot\Models\ChatBotRequest;
use Yaf\Application;
use Yaf\Request\Simple;

/**
 * 测试腾讯闲聊
 */
$app = new Application(APPLICATION_PATH . "/conf/application.ini");
$app->bootstrap();

$config = include APPLICATION_PATH . '/conf/'.ini_get('yaf.environ').'/bot.php';
$config = $config['qq'];
try {
    $cred = new Credential($config['TencentCloud']["SecretId"], $config['TencentCloud']["SecretKey"]);
    $httpProfile = new HttpProfile();
    $httpProfile->setEndpoint("nlp.tencentcloudapi.com");

    $clientProfile = new ClientProfile();
    $clientProfile->setHttpProfile($httpProfile);
    $client = new NlpClient($cred, "ap-guangzhou", $clientProfile);

    $req = new ChatBotRequest();

    /**
     * 请求参数
     *   Query	是	String	用户请求的query
     *   OpenId	否	String	服务的id, 主要用于儿童闲聊接口，比如手Q的openid
     *   Flag	否	Integer	0: 通用闲聊, 1:儿童闲聊, 默认是通用闲聊
     */
    $params = array(
        "Query" => "海口天气"
    );
    $req->fromJsonString(json_encode($params));

    /**
     * 输出参数
     * - 示例：{"Reply":"海口今天最高温度33度，最低温度24度，多云","Confidence":1,"RequestId":"7828dd39-2cad-4686-b8de-51bf9e4bfe5b"}
     *   Reply	String	闲聊回复
     *   Confidence	Float	对于当前输出回复的自信度
     *   RequestId	String	唯一请求 ID，每次请求都会返回。定位问题时需要提供该次请求的 RequestId。
     */
    $resp = $client->ChatBot($req);

    p($resp, true);
} catch(TencentCloudSDKException $e) {
    p($e, true);
}
